/**
 * @author AppleMAC
 */

var Todo = Backbone.Model.extend({
	defaults: {
		title: '',
		completed: false
	}
});
var Todos = Backbone.Collection.extend({
	model: Todo,
	localStorage: new Backbone.LocalStorage('todos-backbone'),
	//url:'abc'
	

});

var firstTodo = new Todo({title: 'Read whole book'});

var todos = new Todos([firstTodo]);
console.log(todos.length);

todos.create({title: 'Try out code examples'});
console.log(todos.length);

var thirdTodo = new Todo({title:'Make something cool'});

todos.add(thirdTodo);
console.log(todos.length);

console.log(todos.models);

var buildTodoView = function  (todoModel, todoController) {
  var base      = document.createElement('div');
  var todoEl    = document.createElement('div');
  
  base.append.child(todoEl);
  
  var render = function() {
  	todoEl.innerHTML = _.template( $('#todoTemplate').html(), {src: todoModel.getSrc()});
  };
  
  todoModel.addSubscriber(render);
  
  todoEl.addEventListener('click', function(){
  	todoController.handleEvent('click', todoModel);
  });
  
  var show = function() {
  	todoEl.style.display = '';
  };
  
  
  var hide = function() {
  	todoEl.style.display = 'none';
  };
  
  return {
  	showview: show,
  	hideview:hide
  };
  
  
};


//Router
var TodoRouter = Backbone.Router.extend({
	routes: { "/filter/:name": "setFilter"},
	setFilter: function(name){console.log("set filter: " + name);}
});

var router = new TodoRouter();
Backbone.history.start();



